<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../../lib/innerIframe-include-ext.js"></script>
<script type="text/javascript" src="../../lib/loader-theme.js"></script>
<script type="text/javascript" src="../../lib/ext/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../lib/ext/plugins/DataTip.js"></script>
<title>签到查询</title>
</head>
<script type="text/javascript">
Ext.require(['*']);
Ext.onReady(function(){
	Ext.QuickTips.init();
    Ext.define('webuser', {
        extend: 'Ext.data.Model',
        fields: [
            'user_id','name','init_date','dt_am','dt_pm'
        ],
       // idProperty: 'user_id'
    });
	
    var store = Ext.create('Ext.data.Store', {
        pageSize: 10,
        model: 'webuser',
        remoteSort: true,
        proxy: {
            type: 'ajax',
            method: 'GET',
            url: '/user/sign_list_teacher',
            reader: {
                type: 'json',
                root: 'data',
                totalProperty: 'count'
            },
            simpleSortMode: true
        },
        sorters: [
            {
                property: 'user_id'
            }
        ]
    });

    var stuStore = Ext.create('Ext.data.Store', {
        pageSize: 10000,
        model: 'webuser',
        remoteSort: true,
        proxy: {
            type: 'ajax',
            method: 'GET',
            url: '/student/list',
            reader: {
                type: 'json',
                root: 'data',
                totalProperty: 'count'
            },
            simpleSortMode: true
        },
    });
    stuStore.loadPage(1);
    
    var grid = Ext.create('Ext.grid.Panel', {
        id:'my_grid',
        store: store,
        loadMask: true,
        region: 'center',
        selModel: Ext.create('Ext.selection.CheckboxModel'),
        columns: [
            {
                text: "学生ID",
                dataIndex: 'user_id',
                hidden: false
            },{
                text: "学生姓名",
                dataIndex: 'name',
                width: 220
            }, {
				text: '签到日期',
				dataIndex: 'init_date',
				width: 220
			}, {
				text: '签到时间',
				dataIndex: 'dt_am',
				width: 220
			}, {
				text: '签退时间',
				dataIndex: 'dt_pm',
				width: 220
			}
        ],
        bbar: Ext.create('Ext.PagingToolbar', {
            store: store,
            displayInfo: true,
            displayMsg: '当前显示  {0} - {1} 共  {2} 条',
            emptyMsg: "没有数据显示！",
            beforePageText: "页码",
			afterPageText: "共 {0} 页",
			firstText:"首页",
			lastText:"末页",
			nextText:"下一页",
			prevText:"上一页",
			refreshText:"刷新"
        }),
        tbar: [{
                xtype: 'combobox',
                id: 'sel_student',
                name: 'sel_student',
                store: stuStore,
                fieldLabel: '学生姓名',
                queryMode: 'local',
                hideTrigger: true,
                minChars: 1,
                matchFieldWidth: true,
                displayField: 'name',
                valueField: 'id',
                labelAlign: 'right'
            },{
                xtype: 'datefield',
                id: 'beginDate',
                name: 'beginDate',
                fieldLabel: '起始日期',
                labelAlign: 'right'
            },{
                xtype: 'datefield',
                id: 'endDate',
                name: 'endDate',
                fieldLabel: '结束日期',
                labelAlign: 'right'
            },{
                xtype: 'button',
                text: '查询',
                handler: function(){
                    if(Ext.getCmp('beginDate').validate() && Ext.getCmp('endDate').validate()){
                        var proxyURL = '/user/sign_list_teacher?';

                        var selName = Ext.getCmp('sel_student').getRawValue();
                        if(selName){
                            proxyURL = proxyURL + '&user_name=' + selName;
                        }

                        var beginDate = mySQLDateFormat(Ext.getCmp('beginDate').getValue());
                        if(beginDate){
                            proxyURL = proxyURL + '&begin_date=' + beginDate;
                        }

                        var endDate = mySQLDateFormat(Ext.getCmp('endDate').getValue());
                        if(endDate){
                            proxyURL = proxyURL + '&end_date=' + endDate;
                        }

                        //alert(proxyURL);
                        store.getProxy().url = proxyURL;
                        store.loadPage(1);
                    }
                }
            }
			]
    });
    store.loadPage(1);
	
	var viewport = Ext.create('Ext.Viewport', {
        id: 'border-example',
        layout: 'fit',
        items: grid
    });

    function reloadStore(){

    };

    function mySQLDateFormat(value){ 
        if(null != value){ 
            return Ext.Date.format(new Date(value),'Ymd'); 
        }else{ 
            return null; 
        } 
    } 
});
</script>
<body>
</body>
</html>
